package controller;

import org.hibernate.Query;
import org.hibernate.Session;

import object.UserAccount;
import util.HibernateUtils;

public class UserAccountController extends HibernateUtils{
	
	public UserAccount authenticate(String username, String password)	{
		Session session = HibernateUtils.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Query query = session.createQuery("from UserAccount where username = :uname and password = :pwd");
		query.setParameter("uname", username);
		query.setParameter("pwd", password);
		UserAccount userAccount = (UserAccount) query.uniqueResult();		
		session.getTransaction().commit();
		if(userAccount != null){
			return userAccount;
		}
		return null;
	}
}
